home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / GMSMTH01.ZIP / DRAW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-08  |  7.8 KB  |  321 lines

  1. /*
  2.  
  3.     draw.c
  4.  
  5.     Internet: alexad3@icebox.iceonline.com
  6.     Copyright 1994, September 26 by Alec Russell, ALL rights reserved
  7.  
  8.     Created - 1994/9/26
  9.  
  10.    Part of the 3D ball demo
  11.  
  12.     History:
  13.         New file
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <conio.h>
  21. #include <alloc.h>
  22. #include <dos.h>
  23. #include <time.h>
  24.  
  25. #include <pr2.h>
  26. #include <palette.h>
  27. #include <readlbm.h>
  28. #include <fstring.h>
  29. #include <g_io.h>
  30. #include <gui.h>
  31. #include <erase.h>
  32. #include <die.h>
  33. #include <gtimer.h>
  34. #include <gmalloc.h>
  35.  
  36. #include <Xlib_all.h>
  37. #include "tank.h"
  38.  
  39.  
  40.  
  41. /* ---------------------- color_cycle_all() ----------- February 10,1995 */
  42. void color_cycle_all(void)
  43. {
  44.    static ULONG next=0l;
  45.  
  46.    if ( next < fast_tick )
  47.       {
  48.       cycle_palette(START_BLUE, NUM_BLUE);
  49.       cycle_palette_reverse(START_RED, NUM_RED);
  50.       cycle_palette_reverse(START_ORANGE, NUM_ORANGE);
  51.  
  52.       next=fast_tick + CYCLE_TIME;
  53.       }
  54. }
  55.  
  56.  
  57. /* ---------------------- draw_back() ----------------- September 6,1994 */
  58. void draw_back(WORD offs)
  59. {
  60.  
  61.    BYTE far *b;
  62.  
  63.    b=far_load("data\\top.pbm");
  64.    if ( b )
  65.       {
  66.       x_put_pbm(0,0, offs, b);
  67.       gfree(b, "top");
  68.       }
  69.    else
  70.       die("top not found");
  71.  
  72.  
  73.    b=far_load("data\\bottom.pbm");
  74.    if ( b )
  75.       {
  76.       x_put_pbm(0,120, offs, b);
  77.       gfree(b, "bottom");
  78.       }
  79.    else
  80.       die("bottom not found");
  81.  
  82.  
  83.    change_font(0);
  84.    xputs(10, 190, offs, WHITE, "Space Rotate, Arrows move, ESC - bye");
  85.  
  86. }
  87.  
  88.  
  89.  
  90. #if 0
  91. /*
  92.  
  93.    ground is a regular arrary of scaled objects
  94.    calc all of visiual positions in relation to players current position
  95.    then DRAW
  96.  
  97.    this is a pretty pathetic routine >:( . AJR 1995
  98.  
  99. */
  100.  
  101.  
  102. #define GRD_SCALEX (INT_TO_FIXED(-150))
  103. #define GRD_SCALEY (INT_TO_FIXED(-130))
  104. #define G_SPACE 80    // distance apart
  105. #define G_GRID  16    // number along the squares edge
  106. #define GH_SPACE (G_GRID/2)
  107. #define GY_ADJUST 17
  108. #define MIN_GZ (INT_TO_FIXED(-10))
  109.  
  110. /* ---------------------- draw_super_ground() ---------- November 5,1994 */
  111. void draw_super_ground(void)
  112. {
  113.    short ix, iy, sx, sy, nw, nh, map_num, start_map_num;
  114.    Fixedpoint dd, cos, sin, x, x0, z, sfx;
  115.    Xform XformToView;
  116.    Point3 XformedPoints, gp;
  117.  
  118.    dd=INT_TO_FIXED(G_SPACE);
  119.    // get aprox position of start grid
  120.    gp.Z=WorldCentre.Z - FixedMul(INT_TO_FIXED(GH_SPACE), dd);
  121.    gp.X=WorldCentre.X - FixedMul(INT_TO_FIXED(GH_SPACE), dd);
  122.  
  123.    // place on nearest grid point
  124.    sx=FIXED_TO_INT(gp.Z)/G_SPACE;
  125.    gp.Z=INT_TO_FIXED(sx*G_SPACE);
  126.    sx=FIXED_TO_INT(gp.X)/G_SPACE;
  127.    sfx=INT_TO_FIXED(sx*G_SPACE);
  128.  
  129.    // calc start bitmap number
  130.    ix=FIXED_TO_INT(sfx);
  131.    iy=ix/NUM_GRD_TYPES;
  132.    nw=iy*NUM_GRD_TYPES;
  133.    start_map_num=map_num=nw - ix;
  134.  
  135.    memset(&XformToView, 0, sizeof(Xform));
  136.    CosSin((TAngle)pl.ViewAngle, &cos, &sin);
  137.    for ( iy=0; iy < G_GRID; iy++)
  138.       {
  139.       gp.X=sfx;
  140.       for ( ix=0; ix < G_GRID; ix++ )
  141.          {
  142.          x=gp.X - WorldCentre.X;  // WorldCentre is where the players tank is at
  143.          z=gp.Z - WorldCentre.Z;
  144.          x0=FixedMul(x, cos) - FixedMul(z, sin);
  145.          z= FixedMul(z, cos) + FixedMul(x, sin);
  146.  
  147.          if ( z < MIN_GZ /* && z > MAX_GZ*/ )  // its in front of us
  148.             {
  149.             XformToView[0][3]=x0;
  150.             XformToView[2][3]=z;
  151.  
  152.             // ConcatXforms(WorldViewXform, tx, XformToView);
  153.  
  154.             XformVec(&XformToView, (Fixedpoint *)&gp,
  155.                   (Fixedpoint *)&XformedPoints);
  156.             
  157.             x=FixedMul(FixedDiv(XformedPoints.X, XformedPoints.Z), GRD_SCALEX);
  158.             sx=((int) ((x + 32768l) >> 16)) + PolyCentreX;
  159.  
  160.             // calc size of bitmap
  161.             x=FixedMul(FixedDiv(INT_TO_FIXED(play_data.grd[map_num].width), XformedPoints.Z), GRD_SCALEX);
  162.             nw=((int) ((x + 32768l) >> 16));
  163.             x=FixedMul(FixedDiv(INT_TO_FIXED(play_data.grd[map_num].height), XformedPoints.Z), GRD_SCALEY);
  164.             nh=((int) ((x + 32768l) >> 16));
  165.  
  166.  
  167.             sy=PolyCentreY - GY_ADJUST;
  168.             sx-=nw>>1;
  169.             sy+=nh;
  170.  
  171.             // DRAW it!
  172.             xscale(sx, sy, nw, nh, play_data.grd[map_num].width,
  173.                           play_data.grd[map_num].height,
  174.                           HiddenPageOffs, play_data.grd[map_num].bmap);
  175.             }
  176.  
  177.          gp.X+=dd;
  178.          ++map_num;
  179.          if ( map_num == NUM_GRD_TYPES )
  180.             map_num=0;
  181.          }
  182.  
  183.       gp.Z+=dd;
  184.       map_num=start_map_num;
  185.       }
  186.  
  187. }
  188. #endif
  189.  
  190.  
  191.  
  192. /* ---------------------- draw_ground() ------------------ August 6,1995 */
  193. void draw_ground(void)
  194. {
  195. }
  196.  
  197.  
  198. /*
  199.  
  200.    angle (hd) is in tenths of degrees
  201.    this draws the sky
  202.  
  203. */
  204. /* ---------------------- draw_strip() --------------- September 14,1994 */
  205. void draw_strip(short x0, short y0, short x1, USHORT off, BYTE far *strip, USHORT hd)
  206. {
  207.    short dw, w2, dw2;
  208.  
  209.    w2=0;
  210.    _fmemcpy(&w2, strip, 1);
  211.  
  212.    dw=(x1 - x0 + 1)>>2;
  213.    hd>>=2;
  214.    if ( hd + dw < w2 )
  215.       x_put_pbm_clipx2(hd, dw, x0, y0, off, strip);
  216.    else
  217.       {
  218.       dw2=w2 - hd;
  219.       dw-=dw2;
  220.       if ( dw2 )
  221.          x_put_pbm_clipx2(hd, dw2, x0, y0, off, strip);
  222.       x0=x0 + (dw2<<2);
  223.       x_put_pbm_clipx2(0, dw, x0, y0, off, strip);
  224.       }
  225.  
  226. }
  227.  
  228.  
  229. /* ---------------------- do_play_draw() ------------- September 26,1994 */
  230. void do_play_draw(void)
  231. {
  232.    short i, n, j;
  233.    Object *ObjectPtr;
  234.    xscale_t far *xb;
  235.  
  236.    pl.num_qdraw=0;
  237.  
  238.    // calc and DRAW ground, DON'T add to draw list
  239.    // draw_super_ground();
  240.    draw_ground();
  241.  
  242.  
  243.    // add the polygons to qdraw list, nearest at start of list
  244.    for ( i=0, ObjectPtr = ObjectListStart.NextObject; i < NumObjects;
  245.          i++, ObjectPtr = ObjectPtr->NextObject )
  246.       {
  247.       if ( !((PObject *)ObjectPtr)->not_draw )
  248.          {
  249.          n=0;
  250.          while ( n <= pl.num_qdraw )
  251.             {
  252.             if ( n == pl.num_qdraw || ((PObject *)ObjectPtr)->CenterInView.Z < pl.qdraw[n].z )
  253.                {
  254.                // make room at position n
  255.                j=pl.num_qdraw - n;
  256.                if ( j )
  257.                   {
  258.                   _fmemmove(pl.qdraw + n + 1, pl.qdraw + n, j*sizeof(qdraw_t));
  259.                   }
  260.                pl.qdraw[n].type=D_POLY;
  261.                pl.qdraw[n].z=((PObject *)ObjectPtr)->CenterInView.Z;
  262.                pl.qdraw[n].obj=ObjectPtr;
  263.                pl.num_qdraw++;
  264.                break;    // from while loop
  265.                }
  266.             else
  267.                n++;
  268.             }
  269.          }
  270.       }
  271.  
  272.    // add the xscale objects
  273.    for ( i=0, xb=play_data.xobjs; i < NUM_XOBJS; i++, xb++ )
  274.       {
  275.       if ( xb->draw )
  276.          {
  277.          n=0;
  278.          while ( n <= pl.num_qdraw )
  279.             {
  280.             if ( n == pl.num_qdraw || xb->vz < pl.qdraw[n].z )
  281.                {
  282.                // make room at position n
  283.                j=pl.num_qdraw - n;
  284.                if ( j )
  285.                   {
  286.                   _fmemmove(pl.qdraw + n + 1, pl.qdraw + n, j*sizeof(qdraw_t));
  287.                   }
  288.                pl.qdraw[n].type=D_XSCALE;
  289.                pl.qdraw[n].z=xb->vz;
  290.                pl.qdraw[n].obj=xb;
  291.                pl.num_qdraw++;
  292.                break;    // from while loop
  293.                }
  294.             else
  295.                n++;
  296.             }
  297.          }
  298.       }
  299.  
  300.    /* Draw all objects */
  301.    for (i=0; i < pl.num_qdraw; i++ )
  302.       {
  303.       switch ( pl.qdraw[i].type )
  304.          {
  305.          case D_POLY:
  306.             DrawPObject((Object *)pl.qdraw[i].obj);
  307.             break;
  308.  
  309.          case D_XSCALE:
  310.             xb=(xscale_t far *)pl.qdraw[i].obj;
  311.             xscale_masked(xb->sx, xb->sy, xb->nw, xb->nh, xb->width, xb->height,
  312.                    HiddenPageOffs, xb->bmap);
  313.             break;
  314.          }
  315.       }
  316. }
  317.  
  318.  
  319. /* ------------------------------ EOF -------------------------------- */
  320.  
  321.